<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/WEB-INF/jsp/common.jsp"%>

<script type="text/javascript">
	var $mainModal = $("#main-loading");
	var usercont = {
		currentPage : 1,
		ajaxList : function(pageNum) {
			$mainModal.modal();
			$("#headBtnGroup").show();
			usercont.currentPage = pageNum;

			searchForm.pageNum.value = pageNum;
			
			$.ajax({
				url : '${basePath}/manage/searchContent',
				method : 'POST',
				data : $("#searchForm").serialize(),
				dataType : 'html',
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);			
				},
				error : function(data) {
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {
						icon : 2
					});
				}
			});

		},
		showSearchBox : function() {
			if ($("#hideBar").css("display") == "none") {
				$("#hideBar").slideDown();
			} else {
				$("#hideBar").slideUp();
			}
		},
		search : function() {
			$mainModal.modal();
			searchForm.pageNum.value = 1;
			$.ajax({
				url : "${basePath}/manage/searchContent",
				method : 'POST',
				data : $("#searchForm").serialize(),
				dataType : 'html',
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);
					
				},
				error : function(data) {
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {
						icon : 2
					});
				}
			});
		},
		reset : function(seqId) {
			$("#searchForm")[0].reset();
		},
		detail : function(seqId){
			$mainModal.modal();
			$("#hideBar").hide();
			$("#headBtnGroup").hide();
			$.ajax({
				url : "${basePath}/manage/contentUserDetail", 
				method: 'POST',
				data : {
					"seqId":seqId
				}, 
				dataType : 'html', 
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);
				},
				error : function(data){
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {icon: 2});
				}
			});
		},
		edit : function(seqId){
			$mainModal.modal();
			$("#hideBar").hide();
			$("#headBtnGroup").hide();
			$.ajax({
				url : "${basePath}/manage/editContentUser", 
				method: 'POST',
				data : {
					"seqId":seqId
				}, 
				dataType : 'html', 
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);
				},
				error : function(data){
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {icon: 2});
				}
			});
		},
		tg: function(fileId){
			$mainModal.modal();
			searchForm.pageNum.value = 1;
			$.ajax({
				url : "${basePath}/manage/contenttg",
				method : 'POST',
				data : {"fileId":fileId,"tgbz":"Y"},
				dataType : 'html',
				success : function(data) {
					$mainModal.modal("close");
					$("#tableBody").html(data);
				},
				error : function(data) {
					$mainModal.modal("close");
					layer.msg("连接服务器时遇到错误！", {
						icon : 2
					});
				}
			});
		},
		btg: function(fileId){
			$mainModal.modal();
			searchForm.pageNum.value = 1;
			
			layer.prompt({
			  formType: 2,
			  maxlength: 255,
			  title: '请输入审核不通过原因',
			  success: function(){
				  $mainModal.modal("close");
			  }
			}, function(value, index, elem){
				if(value.replace(/\s/g,"").length > 0){
					$.ajax({
						url : "${basePath}/manage/contenttg",
						method : 'POST',
						data : {"fileId":fileId, "tgbz":"N","finalRejection":value},
						dataType : 'html',
						success : function(data) {
							$mainModal.modal("close");
							$("#tableBody").html(data);
						},
						error : function(data) {
							$mainModal.modal("close");
							layer.msg("连接服务器时遇到错误！", {
								icon : 2
							});
						}
					});
					layer.close(index);
				}
				else{
					layer.msg('请输入审核不通过原因', {icon: 2});
				}
			});
		},
		save : function(seqId){
			debugger;
			$modal.modal();
			var fileArray = [];
			$("#detailForm input[name='attachmentId']").each(function(){
				if(this.value && this.value.replace(/(^\s+)|(\s+$)/g,"").length > 0)
					fileArray.push(this.value);
			});
			
			$("#detailForm")[0].attachementIds.value = fileArray.join("#");
			$.ajax({
				url : "${basePath}/manage/saveContentUser", 
				method: 'POST',
				data : $("#detailForm").serialize(), 
				dataType : 'html', 
				success : function(data) {
					$modal.modal("close");
					var result = usercont.dealSaveCallback(data);
					if(result == true){
						usercont.close();
					}
				},
				error : function(data){
					$modal.modal("close");
					layer.msg("连接服务器时遇到错误！", {icon: 2});
				}
			}); 
		},
		close : function(){
			usercont.ajaxList(usercont.currentPage);
		},
		del : function(seqId){
			layer.confirm('确定删除这篇资料吗？', {
			  btn: ['确定','取消'] , icon:3 
			}, function(){
				$mainModal.modal();
				$.ajax({
					url : "${basePath}/manage/contentUser/del", 
					method: 'POST',
					data : {"seqId":seqId}, 
					dataType : 'html', 
					success : function(data) {
						$mainModal.modal("close");
						if(data == "true" || data == true){
		  					layer.msg('资料删除成功', {icon: 1});
		  					usercont.ajaxList(usercont.currentPage);
						}
						else{
							layer.msg('资料删除失败', {icon: 2});
						}
					},
					error : function(data){
						$mainModal.modal("close");
						layer.msg("连接服务器时遇到错误！", {icon: 2});
					}
				}); 
			}, function(){});
		},
		dealSaveCallback : function(data){
			if(data == "NO_LG"){
				layer.msg("未获取用户信息，请您先登录！", {icon: 2});
			}
			else if(data == "TT_NP"){
				layer.msg("请输入技术成果名称！", {icon: 2});
			}
			else if(data == "TT_TL"){
				layer.msg("技术成果名称不能超过200个字符！", {icon: 2});
			}
			else if(data == "ST_NP"){
				layer.msg("请输入技术成果简介！", {icon: 2});
			}
			else if(data == "ST_TL"){
				layer.msg("技术成果简介不能超过200个字符！", {icon: 2});
			}

			else if(data == "SB_NP"){
				layer.msg("请输入报送事项！", {icon: 2});
			}
			else if(data == "SB_TL"){
				layer.msg("报送事项不能超过200个字符！", {icon: 2});
			}
			else if(data == "TE_NP"){
				layer.msg("请输入技术成熟度！", {icon: 2});
			}
			else if(data == "TE_TL"){
				layer.msg("技术成熟度不能超过200个字符！", {icon: 2});
			}
			else if(data == "UN_NP"){
				layer.msg("请输入报送单位！", {icon: 2});
			}
			else if(data == "UN_TL"){
				layer.msg("报送单位不能超过200个字符", {icon: 2});
			}
			else if(data == "CP_NP"){
				layer.msg("请输入联系人", {icon: 2});
			}
			else if(data == "CP_TL"){
				layer.msg("联系人不能超过200个字符", {icon: 2});
			}
			else if(data == "PP_NP"){
				layer.msg("请输入联系电话", {icon: 2});
			}
			else if(data == "PP_TL"){
				layer.msg("联系电话不能超过18个字符", {icon: 2});
			}
			else if(data == "PP_CN"){
				layer.msg("联系电话格式不正确", {icon: 2});
			}
			else if(data == "CN_NP"){
				layer.msg("请输入材料内容", {icon: 2});
			}
			else if(data == "SP_NP"){
				layer.msg("请选择专项领域", {icon: 2});
			}
			else if(data == "DB_ER"){
				layer.msg("操作失败！请检查数据有效性。", {icon: 2});
			}
			else {
				return true;
			}
		}
		
	};

	/** 
	 * 建立一个_this对象 
	 * 将查询列表的ajaxList方法赋值给$.ajaxList
	 * 公用分页插件将会使用这个方法分页
	 */
	var _this = {
		_ajaxList : usercont.ajaxList
	}

	$(document).ready(function() {
		usercont.ajaxList(1);
	});
</script>

<div class="admin-content-body">
	<div class="am-cf am-padding am-padding-bottom-0">
		<div class="am-fl am-cf">
			<strong class="am-text-primary am-text-lg">资料查看</strong> / <small>USER</small>
		</div>
	</div>
	<hr>
	<div class="main">
		<div class="am-g">
			<div class="am-u-sm-12" id="headBtnGroup">
				<button type="button" class="am-btn am-btn-default am-btn-xs am-fl"
					onclick="usercont.edit()">
					<span class="am-icon-plus"></span> 新增
				</button>

				<div class="am-fl" id="file-list"
					style="margin-top: 6px; margin-left: 10px"></div>
				<button type="button" class="am-btn am-btn-default am-btn-xs am-fr"
					onclick="usercont.showSearchBox()">
					<span class="am-icon-search"></span> 搜索
				</button>
			</div>
		</div>
		<div class="am-g" style="margin-top: 10px;">
			<div id="hideBar" style="display: none;">
				<%@ include file="searchContent.jsp"%>
			</div>
			<div class="am-u-sm-12 am-u-md-12" id="tableBody"></div>
		</div>
	</div>
</div>
<div class="am-modal am-modal-loading am-modal-no-btn" tabindex="-1"
	id="main-loading">
	<div class="am-modal-dialog">
		<div class="am-modal-hd">正在载入...</div>
		<div class="am-modal-bd">
			<span class="am-icon-spinner am-icon-spin"></span>
		</div>
	</div>
</div>